﻿Imports System.Data.SqlClient

Public Class clsDESTAJOS
    Private cnConn As New SqlConnection
    Private Command As SqlCommand
    Public Function GUARDAR_DIAS(ByVal Tipo As Integer, ByVal Fecha As Date, ByVal CLAVE As Integer, ByVal NOMBRE As String, ByVal CANTIDAD As Double, ByVal TOTAL As Double) As Integer
        Dim cnConnS As New SqlConnection
        cnConnS.ConnectionString = CitraConnection

        Dim Commands As New SqlCommand("spDESTAJOS_DIAS", cnConnS)
        Commands.CommandType = CommandType.StoredProcedure

        Commands.Parameters.Add(New SqlParameter("@TIPO", SqlDbType.Int))
        Commands.Parameters("@TIPO").Value = Tipo
        Commands.Parameters.Add(New SqlParameter("@FECHA", SqlDbType.DateTime))
        Commands.Parameters("@FECHA").Value = Fecha
        Commands.Parameters.Add(New SqlParameter("@CLAVE", SqlDbType.Int))
        Commands.Parameters("@CLAVE").Value = CLAVE
        Commands.Parameters.Add(New SqlParameter("@NOMBRE", SqlDbType.VarChar, 150))
        Commands.Parameters("@NOMBRE").Value = NOMBRE
        Commands.Parameters.Add(New SqlParameter("@CANTIDAD", SqlDbType.Decimal))
        Commands.Parameters("@CANTIDAD").Value = CANTIDAD
        Commands.Parameters.Add(New SqlParameter("@TOTAL", SqlDbType.Decimal))
        Commands.Parameters("@TOTAL").Value = TOTAL
        'Command.Parameters.Add(New SqlParameter("@FECHASTR", SqlDbType.VarChar))
        'Command.Parameters("@FECHASTR").Value = mdatFECHA.ToString("MM/dd/yyyy")
        Dim Lector As SqlDataReader
        Try
            cnConnS.Open()

            Lector = Commands.ExecuteReader
            If Lector.Read() Then
                GUARDAR_DIAS = Lector("NUEVOID")
                cnConnS.Close()
            Else
                If cnConnS.State = ConnectionState.Open Then
                    cnConnS.Close()
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
            If cnConnS.State = ConnectionState.Open Then
                cnConnS.Close()
            End If
        End Try


    End Function
    Public Function GUARDAR_DETALLE(ByVal IDDETALLE As Integer, ByVal IDDIA As Integer, ByVal CLAVE As String, ByVal CANTIDAD As Double, ByVal TOTAL As Double)
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand("spDESTAJOS_DETALLE", cnConn)
        Command.CommandType = CommandType.StoredProcedure

        Command.Parameters.Add(New SqlParameter("@IDDETALLE", SqlDbType.Int))
        Command.Parameters("@IDDETALLE").Value = IDDETALLE
        Command.Parameters.Add(New SqlParameter("@IDDIA", SqlDbType.Int))
        Command.Parameters("@IDDIA").Value = IDDIA
        Command.Parameters.Add(New SqlParameter("@CLAVE", SqlDbType.VarChar, 50))
        Command.Parameters("@CLAVE").Value = CLAVE
        Command.Parameters.Add(New SqlParameter("@CANTIDAD", SqlDbType.Decimal))
        Command.Parameters("@CANTIDAD").Value = CANTIDAD
        Command.Parameters.Add(New SqlParameter("@USUARIO", SqlDbType.VarChar, 150))
        Command.Parameters("@USUARIO").Value = UsuarioActivo
        Command.Parameters.Add(New SqlParameter("@TOTAL", SqlDbType.VarChar, 150))
        Command.Parameters("@TOTAL").Value = TOTAL

        Dim Lector As SqlDataReader

        Try
            cnConn.Open()
            Lector = Command.ExecuteReader
            If Lector.Read() Then
                GUARDAR_DETALLE = Lector("RESULTADO")
                cnConn.Close()
            End If

            cnConn.Close()
        Catch ex As Exception
            'MsgBox(ex.Message, Global.Citra.Herramientas.TiposMensaje.Información, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try

    End Function
    Public Sub INSERTACAPTURA(ByVal CLAVE As String, ByVal EMPLEADO As String)
        Dim sql As String = "Insert Into DESTAJOS_EN_CAPTURA (" & _
                        "CLAVE," & _
                        "NOMBRE," & _
                        "USUARIO)" & _
                        "VALUES (" & _
                        "@CLAVE," & _
                        "@NOMBRE," & _
                        "@USUARIO)"


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("CLAVE", CLAVE)
        Command.Parameters.AddWithValue("NOMBRE", EMPLEADO)
        Command.Parameters.AddWithValue("USUARIO", UsuarioActivo)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
            If RowsAffected > 0 Then
                cnConn.Close()
            Else
                If cnConn.State = ConnectionState.Open Then
                    cnConn.Close()
                End If
            End If
        Catch ex As Exception
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try
    End Sub
    Public Sub ELIMINACAPTURA(ByVal EMPLEADO As String)
        Call SetSqlCitra("DELETE FROM DESTAJOS_EN_CAPTURA WHERE NOMBRE='" & EMPLEADO & "' AND USUARIO='" & UsuarioActivo)
    End Sub
End Class
